package model.utils;

import com.example.towerdefence.R;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.view.View.OnClickListener;

/**
 * Representing the dialog menu which pop ups when a tower must be selected.
 * 
 * @author EvilTeam
 * 
 */
public class CustomDialogMenuForTowerSelection extends Dialog implements
		OnClickListener {

	private static final int FIRE_TOWER = 1;
	private static final int LASER_TOWER = 2;
	private static final int FROST_TOWER = 3;

	private ImageView tower1Img, tower2Img, tower3Img;
	private OnMyDialogResult dialogResult;
	private int imageResultFromDialog;

	public CustomDialogMenuForTowerSelection(Activity parent) {
		super(parent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.tower_select_dialog);
		tower1Img = (ImageView) findViewById(R.id.tower1Img);
		tower2Img = (ImageView) findViewById(R.id.tower2Img);
		tower3Img = (ImageView) findViewById(R.id.tower3Img);
		tower1Img.setOnClickListener(this);
		tower2Img.setOnClickListener(this);
		tower3Img.setOnClickListener(this);

	}

	public void setDialogResult(OnMyDialogResult dialogResult) {
		this.dialogResult = dialogResult;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tower1Img:
			imageResultFromDialog = FIRE_TOWER;
			break;
		case R.id.tower2Img:
			imageResultFromDialog = LASER_TOWER;
			break;
		case R.id.tower3Img:
			imageResultFromDialog = FROST_TOWER;
			break;
		}

		if (dialogResult != null) {
			dialogResult.finish(imageResultFromDialog);
		}
		dismiss();
	}

	public interface OnMyDialogResult {
		void finish(int result);
	}

}